<%-- 
    Document   : index
    Created on : Jan 31, 2013, 1:58:28 AM
    Author     : amr
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <form action="Customers.jsp">
            <input type="text" name="key" value="" /><input type="submit" value="search" />
        </form>
        <sql:setDataSource 
            driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3308/mydb"
            user="root" password="123456"
            var="clients" 
            scope="session" /> 
        <c:if test="${param.key eq null}">
            <sql:query var="am" dataSource="${clients}">
                SELECT *  FROM CUSTOMER
            </sql:query>
        </c:if>
        <c:if test="${param.key ne null}">
            <sql:query var="am" dataSource="${clients}">
                SELECT *  FROM CUSTOMER WHERE first_name LIKE '%${param.key}%' OR last_name LIKE '%${param.key}%' 
            </sql:query>
        </c:if>

        <table border="2" >
            <c:forEach items="${am.rows}" var="row">
                <tr>
                    <td><c:out value="${row.first_name}"/><c:out value="${row.last_name}("/><c:out value="${row.isbn}"/><a href="Profile.jsp?id=${row.id}"><c:out value="${row.email})"/></a></td>
                    <td><c:out value="${row.type}"/></td>
                </tr> 

            </c:forEach> 
        </table> 
    </body>
</html>
